export default {
  state: {
    caches_arr: [],
  },
  mutations: {
    set_caches_arr: function (state, data) {
      let arr = [];
      [...data].map((res, index) => {
        if (!state.caches_arr.includes(res.name) && res.name) {
          if (res.name) {
            arr[index] = res.name;
          }
        }
      });
      let list = [...arr, ...state.caches_arr];
      let set = new Set(list);
      state.caches_arr = [...set.values()];
    },
  },
  actions: {
    text: function (obj) {
      console.log("cache/text", obj);
    },
  },
  getters: {
    caches_key: function (state) {
      return Object.keys(state.caches_arr);
    },
    caches_value: function (state) {
      return Object.values(state.caches_arr);
    },
    caches_name: function (state) {
      return [...state.caches_arr].filter((item) => {
        return !!item;
      });
    },
  },
  namespaced: true,
};
